/*************************************************************
 * File: SpringJaxRsAppConfig.java
 * Copyright (c) 2012
 * Author: Huang Shaobin
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com 
 * Date: Mar 17, 2013
 * Description: 
 ************************************************************/

package snow.core.web.rest.restlet;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.ws.rs.core.Application;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils;

/**
 * TODO
 * 
 * @author Shaobin.Software@gmail.com Shaobin_Software@163.com
 * @version 1.0
 */
public class SpringJaxRsAppConfig extends Application {

	private final Log log = LogFactory.getLog(getClass());

	private List<Object> resources;

	/**
	 * @return
	 * @see javax.ws.rs.core.Application#getClasses()
	 */
	public Set<Class<?>> getClasses() {
		if (CollectionUtils.isNotEmpty(this.resources)) {
			final Set<Class<?>> classes = new HashSet<Class<?>>(this.resources.size());
			for (final Object resource : this.resources) {
				if (resource != null) {
					final Class<?> targetClass = AopUtils.getTargetClass(resource);
					log.debug("Add The Class Of Resource -> " + targetClass);
					classes.add(targetClass);
				}
			}
			return classes;
		}
		return Collections.emptySet();
	}

	public List<Object> getResources() {
		return this.resources;
	}

	public void setResources(List<Object> resources) {
		this.resources = resources;
	}

}
